package com.hns.can.safety.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.DriverInterfaceAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.mainte.vo.LoadFileParamVo;
import com.hns.can.safety.entity.CommSctDobPoitInfoEntity;
import com.hns.can.safety.vo.DrvSctBhvVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.SearchConditionVo;

@Service
public class DrvSctBlackspotService extends CommonService {
	@Autowired
    private FillCodeDscValue codeDscValue;
	
	private <T> List<T> fillColVal(List<T> list) throws Exception{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("drvName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo1 = new FillParamsVo("drvId", map);
		map = new HashMap<String, String>();
		map.put("licPltNo", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo2 = new FillParamsVo("carId", map);
		map = new HashMap<String, String>();
		map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo3 = new FillParamsVo("lineId", map);
		map = new HashMap<String, String>();
		map.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo4 = new FillParamsVo("organId", map);
		codeDscValue.fillInfoValue(list, new String[]{GlobalConst.CACHE_KEY_BASE_DRV_INFO, GlobalConst.CACHE_KEY_BASE_CAR_INFO,
				GlobalConst.CACHE_KEY_BASE_LINE_INFO, GlobalConst.CACHE_KEY_BASE_ORGAN}, vo1, vo2, vo3, vo4);
		return list;
	}
	
	/**
     * 异常行为分页数据
     *
     * @param conditionVo
     * @param request
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
	@Transactional
    @DriverInterfaceAnnotation()
    public Pagination getDrvSctBlackspotPage(SearchConditionVo conditionVo)
            throws Exception {
        Pagination page = this.myBatisPage("drvSctBlackspot.getDrvSctBlackspotCount",
                "drvSctBlackspot.getDrvSctBlackspotList", conditionVo, DrvSctBhvVo.class);
        List list = page.getData();
        fillColVal(list);
        //注入代码描述
        Map<String, String> mapTmp = new HashMap<String, String>();
        mapTmp.put("drvSctBhvName", "DRV00000");
        codeDscValue.fillCodeDscValue(list, mapTmp);
        return page;
    }
	
    
    /**
     * 获取行为疑点报表数据
     * @param params
     * @return
     */
    @SuppressWarnings("unchecked")
	@Transactional
    public List<CommSctDobPoitInfoEntity> getDrvSctBlackspotChart(LoadFileParamVo params) throws Exception {
        List<CommSctDobPoitInfoEntity> list = PubUtil.convertListMapToObject(
                sqlMapDao.selectList("drvSctBlackspot.getDrvSctBlackspotChart", params), CommSctDobPoitInfoEntity.class);
//        QueryFormula.execFormula(list,
//                new String[]{
//                        "drivName,driLicNo->getColsValue(BaseDrvInfoEntity,[drvName,driLicNo],drvId,drvId)",
//                        "licPltNo->getColValue(BaseCarInfoEntity,licPltNo,carId,carId)"
//                });
        fillColVal(list);
        return list;
    }
}
